import sys
from cross_validate import CrossValidate

def main():
  if len(sys.argv) < 8:
    print ('Usage: python train_and_cross_validate.py <fold-prefix> '
        '<train-file> <test-file> <true-data> <output-prefix> '
        '<train-size> <parameter-file>')
    return

  cv = CrossValidate(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
  (lambda_star, train_rmse, test_rmse, weight_star) = cv.run_validation(
      sys.argv[5])
  print('%f %f %f' % (lambda_star, train_rmse, test_rmse))
  pf = open(sys.argv[7], 'a')
  pf.write('%s %f %f %f %s\n' % (sys.argv[6], lambda_star, train_rmse,
        test_rmse, str(weight_star)))
  pf.close()

main()
